-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add EmbeddedModelField #151
Conversation
bec8461
to
a6479ba
Compare
Just want to make sure if we're copying code that we attribute it properly according to the django-nonrel license. |
Certainly. THIRD-PARTY-NOTICES could be amended. |
a6479ba
to
a104694
Compare
cb50893
to
6019a25
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall, LGTM! Before merge, I'd love to go over the commented pieces again, but thank you for transferring the tests. I think they covered all the cases we'd be curious about as well.
This is not at all ready for review. |
6019a25
to
df74d7b
Compare
df74d7b
to
a52ad67
Compare
0db42ed
to
09c1d69
Compare
6f44d29
to
da58861
Compare
e2947b8
to
dd65bb7
Compare
dd65bb7
to
62cafa8
Compare
62cafa8
to
b61cf56
Compare
63a7fad
to
5f5fcd4
Compare
5f5fcd4
to
aed181d
Compare
... | ||
} | ||
|
||
Querying ``EmbeddedModelField`` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should also specify users can query passing in an arbitrary model; however, we do not recommend querying this as results look for an exact match where ordering matters.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This query could work with changes in progress for ArrayField + EMF (implementing EmbeddedModelField.get_db_prep_value()
) but it currently crashes like bson.errors.InvalidDocument: cannot encode object: <Author: Author object (None)>, of type: <class 'model_fields_.models.Author'>
since the model instance isn't transformed to dict. However, I'm very wary of this pattern as I think it will be a huge footgun (the queries work fine initially, then mysteriously break after a schema change... then what is the user to do?).
You can query into an embedded model using the same double underscore syntax | ||
as relational fields. For example, to retrieve all customers who have an | ||
address with the city "New York":: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should also emphasize that you can query using a dictionary, but we that's not
Customer.objects.filter(address={..."city": "New York"})
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think it works. e.g. Book.objects.filter(author={"name": "Shakespeare"})
gives db.model_fields__book.aggregate([{'$match': {'$expr': {'$eq': ['$author', {'name': 'Shakespeare'}]}}}])
. I think you're thinking of Djongo's query syntax.
aed181d
to
07525fe
Compare
e522e32
to
f77e03c
Compare
Rudimentary forms support.
Limited schema change support (no changing of embedded models).
Limited querying support (no field validation (see timgraham#3)
No aggregation support (though much seems to work automagically).
fixes #103